// Removes noise from sensor data
int smooth(int rawIn, int *smooth_array) {
  long total = 0;
  static int i;

  i = (i + 1) % 16;
  smooth_array[i] = rawIn;
  for (int j = 0; j < 16; j++) total += smooth_array[j];
  return total >> 4 ;
}

// Used to average the sensors measurements when everything is level
int findZero(int channel) {
  int zero = 0;
  
  for (int i=0; i< 16; i++) zero += analogRead(channel);
  return zero >> 4;
}

// Allows user to zero gyros on command
void zeroGyros() {
  do {
    rollGyroZero = findZero(ROLL);
  } while (abs(analogRead(ROLL) - rollGyroZero) > ZEROLIMIT);
  
  do {
    pitchGyroZero = findZero(PITCH);
  } while (abs(analogRead(PITCH) - pitchGyroZero) > ZEROLIMIT);

  do {
    yawGyroZero = findZero(YAW);
  } while (abs(analogRead(YAW) - yawGyroZero) > ZEROLIMIT);
}
